package com.zhiwang.planet.widget

import android.content.Context
import androidx.annotation.ColorRes
import androidx.appcompat.app.AlertDialog
import android.view.LayoutInflater
import android.view.View
import com.zhiwang.planet.R
import kotlinx.android.synthetic.main.layout_action_dialog.view.*

class SimpleActionDialog {

    class Builder(private var context: Context) {

        private lateinit var contentText: String

        private lateinit var actionText: String

        @ColorRes
        private var actionTextColor: Int = R.color.appTextColorPrimary

        private var actionTextSize = 14

        private lateinit var listener: View.OnClickListener

        @ColorRes
        private var contentTextColor: Int = R.color.appTextColorPrimary

        fun content(content: String): Builder {
            this.contentText = content
            return this
        }

        fun action(actionText: String, listener: View.OnClickListener): Builder {
            this.actionText = actionText
            this.listener = listener
            return this
        }

        fun actionTextColor(actionTextColor: Int): Builder {
            this.actionTextColor = actionTextColor
            return this
        }

        fun actionTextSize(actionTextSize: Int): Builder {
            this.actionTextSize = actionTextSize
            return this
        }

        fun build() {
            val dialogView = LayoutInflater.from(context).inflate(R.layout.layout_action_dialog, null)

            val alertDialog = AlertDialog.Builder(context)
                    .setView(dialogView)
                    .create()
            alertDialog.show()

            dialogView.positiveTextView.setOnClickListener {
                listener.onClick(it)
                alertDialog.dismiss()
            }

            dialogView.negativeTextView.setOnClickListener {
                alertDialog.dismiss()
            }

        }

        fun buildDefault() {
            build()
        }
    }
}